﻿using Corina.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Corina.Win.ServerHub.Entities
{
    public class ClientInfo : BaseClass
    {
        public ClientInfo() { }

        public ClientInfo(Socket _socket)
        {
            Client = _socket;
            IPAddress = ((IPEndPoint)Client.RemoteEndPoint).Address.ToString();
            Port = ((IPEndPoint)Client.RemoteEndPoint).Port;
        }

        private string _guid = System.Guid.NewGuid().ToString();
        public string Guid
        {
            get { return _guid; }
            set
            {
                _guid = value;
                RaisePropertyChanged(() => Guid);
            }
        }

        public Socket Client { get; set; }

        private DateTime _entryTime = DateTime.Now;
        public DateTime EntryTime
        {
            get { return _entryTime; }
            set
            {
                _entryTime = value;
                RaisePropertyChanged(() => EntryTime);
            }
        }

        public string Address
        {
            get
            {
                //return string.Format("{0}:{1}", ((IPEndPoint)Client.RemoteEndPoint).Address, ((IPEndPoint)Client.RemoteEndPoint).Port);
                return string.Format("{0}:{1}", IPAddress, Port);
            }
        }

        private string _ipaddress = string.Empty;
        public string IPAddress
        {
            get { return _ipaddress; }
            set {
                _ipaddress = value;
                RaisePropertyChanged(() => IPAddress);
            }
        }

        private int _port = 0;
        public int Port
        {
            get { return _port; }
            set {
                _port = value;
                RaisePropertyChanged(() => Port);
            }
        }

        //public string IPAddress
        //{
        //    get { return ((IPEndPoint)Client.RemoteEndPoint).Address.ToString(); }
        //}

        //public int Port
        //{
        //    get { return ((IPEndPoint)Client.RemoteEndPoint).Port; }
        //}
    }
}
